package com.example.video.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.video.mapper.PlatformMapper;
import com.example.video.entity.Platform;
import com.example.video.service.IPlatformService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiusuyang
 * @since 2024-04-17
 */
@Service
public class PlatformServiceImpl implements IPlatformService {

    @Resource
    private PlatformMapper mapper;

    @Override
    public Platform getItem(Integer platformId) {
        return mapper.selectById(platformId);
    }

    @Override
    public List<Platform> getAll() {

        return mapper.selectList(new QueryWrapper<>());
    }


    @Override
    public List<Platform> getList(Integer page, Integer size) {
        QueryWrapper<Platform> qwrapper = new QueryWrapper<>();
        IPage<Platform> iPage = mapper.selectPage(new Page<>(page,size),qwrapper);
        return iPage.getRecords();
    }

    @Override
    public long  GetCount() {
        return mapper.selectCount(new QueryWrapper<>());
    }

    @Override
    public boolean add(Platform platform) {
        return mapper.insert(platform) > 0;
    }

    @Override
    public boolean modify(Platform platform) {
        return mapper.updateById(platform) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return mapper.deleteById(id) > 0;
    }

    @Override
    public Platform getItemByName(String platformName) {
        return mapper.selectOne(new QueryWrapper<Platform>().eq("platform_name", platformName));
    }

    @Override
    public String getPlatformNameById(Integer id) {
        Platform platform = mapper.selectOne(new LambdaQueryWrapper<Platform>().eq(Platform::getId, id));
        return platform.getPlatformName();
    }
}
